/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package inputverifier;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author Gebruiker
 */
public class LengthVerifier extends InputVerifier {

    private int max;
    public LengthVerifier(int max){
        super();
        this.max = max;
    }
    
    @Override
    public boolean verify(JComponent input) {
        if(input instanceof JTextField){
            String text = ((JTextField)input).getText();
//            if(text.length() == 0){
//                JOptionPane.showMessageDialog(input.getParent(),"Gelieve dit veld in te vullen.","Error",JOptionPane.ERROR_MESSAGE);
//                return false;
//            }
            if(text.length()>max){
                JOptionPane.showMessageDialog(input.getParent(),"Dit veld mag maximum "+max+" tekens bevatten.","Error",JOptionPane.ERROR_MESSAGE);
                return false;
            }
            return true;
        }
        
        throw new UnsupportedOperationException("Deze verifier is niet van toepassing op dit soort componenten.");
    }
    
}
